import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:magic_car/common/nodata.dart';
import 'package:magic_car/res/colors.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:shared_preferences/shared_preferences.dart';
//子页面
class FaultCodePage extends StatefulWidget {
 final String queryid;

  FaultCodePage(this.queryid);

  @override
  _ChildItemViewState createState() => _ChildItemViewState();
}

class _ChildItemViewState extends State<FaultCodePage> {
  List codelist=[];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getqueryinfo();

  }
  getqueryinfo() async{
     EasyLoading.show(status: "正在查询");
    Map<String, String> param = new Map();
    SharedPreferences pref = await SharedPreferences.getInstance();
    param["uid"] = pref.getString('uid');
    param['id'] = widget.queryid;
  
    HttpHelper.post(HttpHelper.API_QueryHistoryinfo, (data) async {
      EasyLoading.dismiss();
      if (data != null) {
        for (var item in  data['info']['problem']) {
          for(var codes in item["codeList"]){
            codes['time'] = item['updateTime'];
          }
          codelist.addAll(item["codeList"]);
        }
        setState(() {
          codelist = codelist;
        });
      }
    
    }, params: param);
  }
  @override
  Widget build(BuildContext context) {
    return
    Scaffold(appBar:
    new AppBar(title: Text("历史故障"),backgroundColor: Colors.white,elevation: 0,)
     ,body:
     Container(
       child:codelist.length==0?Nodata(): new ListView.builder(itemBuilder: (BuildContext context,int index){
        return new Container(
          color: Colors.white,
          margin: new EdgeInsets.all(10),
          padding: new EdgeInsets.all(10),
          child: Column(
            mainAxisAlignment:MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(codelist[index]["code"],style: TextStyle(color: Colours.bj_red_r2,fontSize: 18),),
              Container(height: 5,),
               Text(codelist[index]["system_name"],style: TextStyle(color: Colours.bj_orange_o2,fontSize: 15),),
               Container(height: 5,),
                Text(codelist[index]["description"],style: TextStyle(color: Colors.black45,fontSize: 14),),
                Container(height: 5,),
                 Text("状态："+codelist[index]["status"],style: TextStyle(color: Colors.black45,fontSize: 14),),
                 Container(height: 5,),
                 Text('时间：'+codelist[index]["time"],style: TextStyle(color: Colors.black45,fontSize: 14),)

            ],
          ),
        );
       },itemCount: codelist.length,)),
     
    );
    
  }
}